package services;

import domain.entities.Compromisopais;
import domain.entities.Mail;
import domain.entities.MailDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: vgonzalez
 * Date: 30/08/12
 * Time: 16:24
 * To change this template use File | Settings | File Templates.
 */

@Service
public class MailService<Mail> implements CRUDService<Mail> {

    private MailDAO mailDAO;

    public MailService() {
    }

    @Autowired
    public MailService(MailDAO mailDAO) {
        this.mailDAO= mailDAO;
    }

    public List<domain.entities.Mail> findByPais(String pais){
        return mailDAO.findByPais(pais);
    }

    public void save(domain.entities.Mail mail){
        this.mailDAO.save(mail);
    }

    public domain.entities.Mail findById(Integer id){
        return mailDAO.findById(id);
    }

    @Override
    public <V extends Criteria> List<Mail> list(V criteria) {
        List<Mail> list = mailDAO.findAll();
        Iterator<Mail> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }
}
